/**
*
* 2007-11-2 下午08:33:57
* @author xuhuan
*/

package edu.ccut.saturn.studio.logic.model.xml.loader;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import edu.ccut.saturn.studio.logic.model.Shape;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnEndNode;
import edu.ccut.saturn.studio.logic.model.saturn.SaturnParameter;

public class EndNodeLoader extends NodeLoader {
	
	public List<Shape> loadNodes(Element root) {
		
		NodeList startNodes = root.getElementsByTagName(SaturnEndNode.KEY_NODE_END);
		
		List<Shape> shapes = new ArrayList<Shape>(startNodes.getLength());
		
		for (int i = 0; i < startNodes.getLength(); ++i) {
			SaturnEndNode saturnEndNode = new SaturnEndNode();
			
			Node endNode = startNodes.item(i);
			String shapeId = super.getNodeAttributeValue(endNode, Shape.KEY_ATTRIBUTE_SHAPE_ID);
			String nextId = super.getNodeAttributeValue(endNode, Shape.KEY_ATTRIBUTE_SHAPE_NEXT_ID);
			String name = super.getNodeElementValue(endNode, SaturnEndNode.SHOW_END_NODE_NAME);
			String description = super.getNodeElementValue(endNode, SaturnEndNode.SHOW_END_NODE_DESCRITPION);
			List<SaturnParameter> parameters = super.getParameters(endNode);
			
			Point location = super.getLocation(endNode);
			Dimension size = new Dimension(50, 70);
			
			saturnEndNode.setNode(endNode);
			saturnEndNode.setId(shapeId);
			saturnEndNode.setLocation(location);
			saturnEndNode.setName(name);
			saturnEndNode.setNextId(nextId);
			saturnEndNode.setDescription(description);
			saturnEndNode.setParameters(parameters);
			saturnEndNode.setSize(size);
			
			shapes.add(saturnEndNode);
		}
		
		return shapes;
	}
}
